<?php
namespace app\pc\controller;

class Mail extends Common
{

    public function index()
    {
        return $this->fetch();
    }
    //发送站内信
    public function add()
    {
        $input = ArrRemoveJs(postJsonToArray());
        $MailModel = new \app\api\model\Mail();
        $result = $MailModel->add($input);
        if($result['error'] != 0)
        {
            $this->error($result['msg']);
        }
        else
        {
            exit($result['msg']);
        }
    }


    public function upload_photo()
    {
        // 获取表单上传文件
        $file = request()->file('file');
        $path =  'public' . DS . 'uploads'. DS . "email";
        if(empty($file)) return json_encode(['error'=>1,'msg'=>'没有上传图片'],JSON_UNESCAPED_UNICODE);
        $info = $file->validate(['size'=>1048576,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . $path);
        if($info){
            // 成功上传后 获取上传信息
            // 输出 jpg
            $img_path = str_replace('\\','/',$path.DS.$info->getSaveName());
            return json_encode([
                'error' => 0,
                'msg'   => $this->config('domain')."/".$img_path
            ]);

        }else{
            return json_encode([
                'error' => 1,
                'msg'   => $file->getError()
            ],JSON_UNESCAPED_UNICODE);
        }
    }
}